<?php
  include_once("../sql_connect.php");
  include_once("../msg_redirect.php");
?>
<?php
/*使用Ajax调用该关注模块将要关注人的信息写入数据库*/

/*取回被关注者的u_no*/
$c_name = $_POST[name];

$my_sql = mysql_query("select u_no from user_info where u_name = '$c_name'");
$my_result = mysql_fetch_array($my_sql);

/*将被关注者的u_no赋值给$c_no，把自己的u_no赋值给$u_no*/
$c_no = $my_result[u_no];
$u_no = $_COOKIE['u_no'];

/*在concerns中查看是否该人已经被自己关注*/
$if_concerns = true;
$my_sql = mysql_query("select * from concerns where u_no = '$u_no' and c_no = '$c_no'");
if (mysql_num_rows($my_sql) == 1) {
	$if_concerns = false;
	echo $if_concerns;
}
else {
	/*检查 concerns表中得最大concerns编号*/
	$my_sql = mysql_query("select MAX(no) from concerns");	
	$my_result = mysql_fetch_array($my_sql);
		
	/*对将要输入concerns表的no字段进行赋值*/
	$no = $my_result[0] + 1;
	
	/*检查 concerns表中得最大c_num编号*/
	$myconcerns_sql = mysql_query("select MAX(c_num) from concerns where u_no = '$u_no'");	
	$myconcerns_result = mysql_fetch_array($myconcerns_sql);
		
	/*对将要输入concerns表的c_num字段进行赋值*/
	$c_num = $myconcerns_result[0] + 1;
	
	/*检查 concerns表中得最大f_num编号*/
	$myfun_sql = mysql_query("select MAX(f_num) from concerns WHERE c_no='$c_no'");	
	$myfun_result = mysql_fetch_array($myfun_sql);
		
	/*对将要输入concerns表的f_num字段进行赋值*/
	$f_num = $myfun_result[0] + 1;

	/*插入数据到关注表*/
	mysql_query("insert into concerns values('$no','$u_no','$c_no','$c_num','$f_num')");
	$if_concerns = true;
	echo $if_concerns;
}
return ;
?> 